import { defineStore } from 'pinia';
import workApi from "@/http/workApi";

export const useAdminStore = defineStore('admin', {
    actions: {
        setAcademy() {
            workApi.get('admin/college_profession').then((res) => {
                // 把二级学院存到pinia
                res.data.map((s) => {
                    s.label = s.college
                    s.value = s.id
                    return s
                })
                for (let i = 0; i < res.data.length; i++) {
                    res.data[i].children.map((s) => {
                        s.label = s.profession
                        s.value = res.data[i].id + '-' + s.id
                    })
                }
                this.academy = res.data
            })
        },
        setTeacher() {
            workApi.get('admin/teacher').then((res) => {
                this.teacher = res.data
            })
        },
        setStudents(){
            workApi.get('admin/student').then((res)=>{
                this.students = res.data
            })
        },
        setClass(){
            workApi.get('admin/class').then((res)=>{
                res.data.enable.map((s)=>{
                    s.value = s.id
                    s.label = s.class_name
                    return s
                })
                res.data.disable.map((s)=>{
                    s.value = s.id
                    s.label = s.class_name
                    return s
                })

                this.class=res.data
            })
        },
        updateTrain() {
            workApi.get('admin/training').then((res)=>{
                this.train = res.data
            })
        },
    },


    state: () => ({
        // 二级学院
        academy:[],
        // 教师
        teacher:[],
        // 班级,
        class:[],
        // 学生
        students:[],
        // 实训信息
        train:[],
    }),

    getters: {
        getOrganization() {
            return [{
                name: '深圳技师学院',
                label: '深圳技师学院',
                id: '00000',
                value: '00000',
                children: this.academy
            }]
        },
    },
})
